/**
 * 事件监听
 */
class Bus {
    constructor() {
        this.map = {};
    }

    $on(name, handler) {
        this.map[name] = this.map[name] || [];
        this.map[name].push(handler);
    }

    $emit(name, ...args) {
        if (this.map[name]) {
            this.map[name].forEach((handler) => handler(...args));
        }
    }
}

Bus.install = function(_Vue) {
    _Vue.prototype.$bus = new Bus();
};

export default Bus;
